import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service 数据源信息
 * @since 2018-8-23
 * @version 0.0.1

 */
import request from 'utils/request';
import { CPAAS_IMP } from 'utils/config';
/**
 * 数据源查询接口
 * @async
 * @function fetchDataBaseList
 * @param {Object} params - 查询参数
 * @param {String} params.page - 页码
 * @param {String} params.size - 页数
 */

export function fetchDataBaseList(_x) {
  return _fetchDataBaseList.apply(this, arguments);
}
/**
 * 新增数据源信息
 * @async
 * @function createDatabase
 * @param {Object} params - 参数
 */

function _fetchDataBaseList() {
  _fetchDataBaseList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_IMP, "/v1/imported/database/list"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchDataBaseList.apply(this, arguments);
}

export function createDatabase(_x2) {
  return _createDatabase.apply(this, arguments);
}
/**
 * 更新数据源
 * @async
 * @function updateDatabase
 * @param {Object}} params.body -修改的数据
 */

function _createDatabase() {
  _createDatabase = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_IMP, "/v1/imported/database/info"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _createDatabase.apply(this, arguments);
}

export function updateDatabase(_x3) {
  return _updateDatabase.apply(this, arguments);
}
/**
 * 删除数据源信息
 * @async
 * @function deleteDataBase
 * @param {Object} params - 参数
 * @param {String} params.databaseId - 数据源id
 */

function _updateDatabase() {
  _updateDatabase = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_IMP, "/v1/imported/database/info"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _updateDatabase.apply(this, arguments);
}

export function deleteDataBase(_x4) {
  return _deleteDataBase.apply(this, arguments);
}
/**
 * 删除数据源信息
 * @async
 * @function connectTest
 * @param {Object} params - 参数
 * @param {String} params.databaseId - 数据源id
 */

function _deleteDataBase() {
  _deleteDataBase = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_IMP, "/v1/imported/database/info/").concat(params.databaseId), {
              method: 'DELETE'
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _deleteDataBase.apply(this, arguments);
}

export function connectTest(_x5) {
  return _connectTest.apply(this, arguments);
}

function _connectTest() {
  _connectTest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_IMP, "/v1/imported/database/testConnecting/").concat(params.databaseId), {
              method: 'POST'
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _connectTest.apply(this, arguments);
}